home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 4.3 KB | 125 lines | [TEXT/MPS ] |
- ;=============================================================================
- ; UMemory assembly language routines
- ;
- ; Copyright © 1987-1990 Apple Computer, Inc. All rights reserved.
- ;
- Blanks On
- String AsIs
- Case On
-
- Print Off
- Include 'Macros.a'
- If not qNeedsROM128K then
- INCLUDE 'SysEqu.a'
- INCLUDE 'Traps.a'
- endif
-
- LOAD 'ProgStrucMacs.d'
- LOAD 'FlowCtlMacs.d'
- Print On
-
-
- ;---------------------------------------------------------------------------------------------------
- ; PROCEDURE ALoadMacAppSeg;
- ; This is the actual patch for LoadSeg. It sets up the stack so that we
- ; can call FUNCTION LoadMacAppSegment (segNum: INTEGER): LONGINT.
-
- Seg 'MAMemoryRes'
- EXPORT PROCEDURE ALOADMACAPPSEG(theSegNum:W)
-
- BEGIN Save=D0-D2/A0-A2
- IMPORT LOADMACAPPSEGMENT, POSTLOADMACAPPSEGMENT
-
- CALL LOADMACAPPSEGMENT:L(theSegNum(FP):W),A0
-
- Move.W theSegNum(FP),-(SP) ; push the original parameter to loadseg
- PEA ComeBack+6 ; push a return address
- ; loadseg will knock 6 off the return address
- Jmp (A0) ; Call the original loadseg
-
- ComeBack
- CALL POSTLOADMACAPPSEGMENT ; call back to Pascal again
-
- Sub.L #6,4(FP) ; jerk our return address just like loadseg does
- ; Return ; Return to the real world
- ; the Return macro doesn't preserve the A0 register because it generates the following code
-
- ;00000026: 4CDF 0707 'L...' MOVEM.L (A7)+,D0-D2/A0-A2
- ;0000002A: 4E5E 'N^' UNLK A6
- ;0000002C: 205F ' _' MOVEA.L (A7)+,A0
- ;0000002E: 544F 'TO' ADDQ.W #$2,A7
- ;00000030: 4ED0 'N.' JMP (A0)
-
- ; So… we'll just have to take over from the computers and land this puppy by hand
-
- MOVEM.L (A7)+,D0-D2/A0-A2
- UNLK A6
- MOVE.L (A7),2(A7) ; move the return address into the place of the
- ; parameter because we will destroy the stack-frame
- ; that includes the parameter and then just RTS
- ; This assumes intimate knowledge (!) of the fact that
- ; this function only has a single parameter that is
- ; an integer (2 bytes)
- ADDQ.W #$2,A7 ; Destroy the stack frame just like I told you
- RTS ; We're outta here with A0 preserved
- EndP
-
- ;---------------------------------------------------------------------------------------------------
- ; FUNCTION PreLoadSegment;
- ; This function preloads a segment in both the resource manager sense and the
- ; segment loader sense.
-
- Seg 'MAMemoryRes'
- EXPORT FUNCTION PRELOADSEGMENT(theSegNum:W):B
-
- BEGIN Save=D0-D2/A0-A2
- IMPORT PRELOADSEGMENTRESOURCE, LOADMACAPPSEGMENT, POSTLOADMACAPPSEGMENT
- ; preload the resource so our call to the seg loader patch won't fail
-
- CALL PRELOADSEGMENTRESOURCE:B(theSegNum(FP):W),D0
- TST.B D0
- BNZ.S success
- ;segment didn't load
-
- Move.B #0, PRELOADSEGMENT(FP)
- BRA.S exit
-
-
- success
- CALL LOADMACAPPSEGMENT:L(theSegNum(FP):W),A0
-
- ;thank-you François Grieu
- If not qNeedsROM128K then
- TST.W ROM85
- BPL.S @dontFixIt ; if it isn't broken…
- MOVE.L A0,-(A7) ; save old _LoadSeg address
- SUBQ.L #4,A7 ; make some room for _GetResourceresult
- MOVE.L #'CODE',-(A7) ; get the CODE resource (once more…)
- MOVE.W theSegNum(FP),-(SP) ; push the segment number
- _GetResource ; this can't fail, it has just been checked
- MOVE.L (A7)+,A0 ; handle to the code resource
- MOVE.L (A0),A0 ; points to first word of the code resource
- MOVE.W (A0),D0 ; offset of first entry in the jump table
- LEA 2(A5,D0.W),A0 ; the offset thou shall use shall be two
- ADD.W CurJTOffset,A0 ; points to the first routine entry point
- CMPI.W #$4EF9,(A0) ; is it a JMP.L ?
- MOVEA.L (A7)+,A0 ; restore old _LoadSeg address
- BEQ.S ComeBack ; the segment is already loaded
- @dontFixIt
- endif
-
- Move.W theSegNum(FP),-(SP) ; push the original parameter to loadseg
- PEA ComeBack+6 ; push a return address
- ; loadseg will knock 6 off the return address
- Jmp (A0) ; Call the original loadseg
-
- ComeBack
- CALL POSTLOADMACAPPSEGMENT ; call back to Pascal again
-
-
- Move.B #1, PRELOADSEGMENT(FP)
- exit
- Return ; Return to the real world
-
- END
-